home *** CD-ROM | disk | FTP | other *** search
-
- **********************************************************
- * BB2Exe v1.0 22.12.1994 *
- **********************************************************
- * copyright (c) 1994 by Jens Tröger, all rights reserved *
- * this is Public Domain *
- **********************************************************
- * written using HiSoft`s DevPac 3.04 *
- * thanx to Francois Rouaix who puts the C source into PD *
- * greets fly to Oliver Reiff, "PackMAN" Falk Zühlsdorff *
- * "Janosh" Jan Stötzer, Jan van den Baard,... *
- **********************************************************
- * (non)sense: this will read the Bootblock from a given *
- * floppy-drive and then write to an executable *
- * works with KS1.2 and better *
- * USAGE: BB2Exe <unit> <file> *
- **********************************************************
-
- opt o+,p+
-
- move.l a0,a5
-
- ; ----- alloc memory for bootblock and several structures
-
- alloc_mem move.l 4.w,a6
- move.l #1024+88,d0 ; Bootblock + Port/IO...
- move.l #$10001,d1
- jsr -198(a6) ; _LVOAllocMem
- move.l d0,a4 ; a4: PTR to mem
- beq exit
-
- ; ----- open dos.library
-
- open_dos lea dosname(pc),a1
- moveq #33,d0
- jsr -552(a6) ; _LVOOpenLibrary
- move.l d0,d6 ; d6: DOSBase
- beq free_mem
-
- ; ----- get unit
-
- read_unit cmp.b #"d",(a5)+
- bne usage
- cmp.b #"f",(a5)+
- bne usage
- moveq #0,d0
- move.b (a5)+,d0
- sub.b #48,d0
- cmp.b #4,d0
- bge usage
- cmp.b #0,d0
- blt usage
- move.l d0,d2 ; d2: Unit
- cmp.b #":",(a5)+
- bne usage
- adda.l #1,a5
- move.l a5,a0
- .loop cmp.b #10,(a0)+
- bne.s .loop
- move.b #0,-(a0)
-
- ; ----- add MessagePort to system
-
- add_port sub.l a1,a1
- jsr -294(a6) ; _LVOFindTask
- move.l d0,1024+16(a4)
- lea 1024(a4),a1
- jsr -354(a6) ; _LVOAddPort
-
- ; ----- open trackdisk.device
-
- open_track lea trackname(pc),a0
- lea 1024+32(a4),a1 ; a1: DiskIO-Struc
- move.l d2,d0
- moveq #0,d1
- jsr -444(a6) ; _LVOOpenDevice
- tst.l d0
- bne err_nodev ; FATAL !!!!!
-
- ; ----- read bootblock
-
- read_bb lea 1024+46(a4),a0 ; a0: RepPort
- lea 1024(a4),a1 ; a1: ReplyPort-Struc
- move.l a1,(a0)
- lea 1024+32(a4),a1 ; a1: DiskIO-Struc
- move.w #2,28(a1)
- move.l #1024,36(a1)
- move.l a4,40(a1)
- move.l #0,44(a1)
- jsr -456(a6) ; _LVODoIO
- move.l d0,d2
- move #9,28(a1)
- move.l #0,36(a1)
- jsr -456(a6) ; _LVODoIO
- tst.l d2
- bne err_nodoio
-
- ; ----- close trackdisk.device
-
- close_dev lea 1024+32(a4),a1 ; a1: DiskIO-Struc
- jsr -450(a6) ; _LVOCloseDevice
-
- ; ----- remove port
-
- rem_port lea 1024(a4),a1 ; a1: ReplyPort
- jsr -360(a6) ; _LVORemPort
-
- ; ----- open exe-file
-
- open_exe move.l d6,a6
- move.l #1006,d2 ; MODE: NEW_FILE
- move.l a5,d1
- jsr -30(a6) ; _LVOOpen
- move.l d0,d7 ; d7: File-Handle
- beq no_open
-
- ; ----- write
-
- write lea hunk_tab1(pc),a2 ; hunk_header
- moveq #40,d3
- bsr write_exe
- cmp.l #40,d0
- bne no_write
-
- lea 12(a4),a2 ; code
- move.l #1012,d3
- bsr write_exe
- cmp.l #1012,d0
- bne.s no_write
-
- lea hunk_tab2(pc),a2 ; hunk_end
- moveq #4,d3
- bsr.s write_exe
- cmp.l #4,d3
- bne.s no_write
-
- ; ----- close up clearly
-
- close_file move.l d7,d1
- jsr -36(a6) ; _LVOClose
-
- ; ----- close dos.library
-
- close_dos move.l 4.w,a6
- move.l d6,a1
- jsr -414(a6) ; _LVOCloseLibrary
-
- ; ----- free allocated memory
-
- free_mem move.l a4,a1
- move.l #1024+88,d0
- jsr -210(a6) ; _LVOFreeMem
-
- ; ----- returncode: 0
-
- exit moveq #0,d0
- rts
-
- ; ----- several messages
-
- usage lea usage_text(pc),a2
- move.l #usage_text_end-usage_text,d3
- bsr.s write_msg
- bra close_dos
-
- err_nodev lea err1_text(pc),a2
- moveq #38,d3
- bsr.s write_msg
- move.l 4.w,a6
- lea 1024(a4),a1 ; a1: ReplyPort
- jsr -360(a6) ; _LVORemPort
- bra.s close_dos
-
- err_nodoio lea err2_text(pc),a2
- moveq #44,d3
- bsr.s write_msg
- move.l 4.w,a6
- lea 1024+32(a4),a1 ; a1: DiskIO-Struc
- jsr -450(a6) ; _LVOCloseDevice
- lea 1024(a4),a1 ; a1: ReplyPort
- jsr -360(a6) ; _LVORemPort
- bra.s close_dos
-
- no_open lea err3_text(pc),a2
- moveq #25,d3
- bsr.s write_msg
- bra close_dos
-
- no_write lea err4_text(pc),a2
- moveq #37,d0
- bsr.s write_msg
- bra.s close_file
-
- ; ----- this writes data to exe-file
-
- write_exe move.l d7,d1
- move.l a2,d2
- jmp -48(a6) ; _LVOWrite
-
- ; ----- write text to stdout
-
- write_msg move.l d6,a6
- jsr -60(a6) ; _LVOOutput
- move.l d0,d1
- move.l a2,d2
- jmp -48(a6) ; _LVOWrite
-
- ; ----- names, texts
-
- dosname dc.b "dos.library",0
- even
- trackname dc.b "trackdisk.device",0
- even
- err1_text dc.b "FATAL ERROR opening trackdisk.device.",10
- even
- err2_text dc.b "Error reading Bootblock. No disk inserted ?",10
- even
- err3_text dc.b "Cannot open Output-File.",10
- even
- err4_text dc.b "Error writing to File. Aborting.",10
- even
- usage_text dc.b 10,$9b,"1mBB2Exe v1.0",$9b,"0m 1994 by Jens Tröger",10
- dc.b "USAGE: BB2Exe <unit> <file>",10
- dc.b "Where <unit> is one of your mounted floppies (df0:) "
- dc.b "and <file> is the Path/Name of the file.",10,10
- usage_text_end
-
- ; ----- NOTE: MY Amiga does not accept only one hunk, so I added a dummy
- ; ----- hunkt to the executable file with size of 1 long (4 bytes...) but
- ; ----- the curious thing is that this hunkt is NOT placed into the exe-
- ; ----- file...
- ; ----- NOTE: The system loads a6 with ExecBase BEFORE the bootcode runs
- ; ----- and so the bootcode does not need to load ExecBase. Thats why I
- ; ----- add the OpCode $2c780004 as the first instruction, cause many
- ; ----- bootcodes dont load ExecBase (I always code this way...)
- ; ----- NOTE: I dont care for initialised io-struc of trackdisk.device
- ; ----- which is placed by the system in a1 (THIS COULD CAUSE A TRASH)
- ; ----- NOTE: much bootcode writes directly to memory, which was NOT
- ; ----- allocated (they write direct to chip-ram so they may overwrite
- ; ----- YOUR code -> TRASH)
-
- ; ----- SO BE CAREFUL EXECUTING A BOOTBLOCK !!!!!!!!!!!!!!!!!
-
- hunk_tab1 dc.l $000003f3 ; huk_header
- dc.l $00000000 ; no names
- dc.l $00000002 ; 2 hunks to load (*)
- dc.l $00000000 ; first hunk - hunk 0
- dc.l $00000001 ; last hunk - hunk 1
- dc.l $000000fe ; size of first hunk (code)
- dc.l $00000001 ; siza of second hunk (dummy)
-
- dc.l $000003e9 ; start of code
- dc.l $000000fe ; length of code
-
- dc.l $2c780004 ; OpCode: move.l 4.w,a6
-
- hunk_tab2 dc.l $000003f2 ; hunk_end
-
- end
-